package com.tanhua.server.controller;


import com.tanhua.model.vo.ReportVo;
import com.tanhua.model.vo.SurveyVo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    // 问卷列表
    @GetMapping
    public ResponseEntity testSoul(){
        List<SurveyVo> vos = testSoulService.testSoul();
        return ResponseEntity.ok(vos);
    }

    // 提交问卷
    @PostMapping
    public ResponseEntity testSubmit(@RequestBody Map map){
        List<HashMap> vo = (List<HashMap>) map.get("answers");
        String resultId = testSoulService.testSbumit(vo);
        return ResponseEntity.ok(resultId);
    }

    // 查看结果
    @GetMapping("/report/{id}")
    public ResponseEntity report(@PathVariable("id") Long reportId){
        ReportVo vo = testSoulService.SeeReport(reportId);
        return ResponseEntity.ok(vo);
    }

}
